package RMIBank;

import java.rmi.Naming;

public class ClientMain {

    public static void main(String[] args) {
        Bank bank = null;

        try {
            bank = (Bank) Naming.lookup("rmi://localhost/RMIBank/Bank");
        } catch (Exception ex) {
            System.out.println("Connection to RMI Bank failed! Is the server running?\n");
        }

        if (bank != null) {

            try {
                //Create accounts.
                Account allan = bank.getAccount("Allan");
                Account nick = bank.getAccount("Nick");
                Account dennis = bank.getAccount("Dennis");
                Account morten = bank.getAccount("Morten");

                //Deposit money.
                allan.deposit(500);
                nick.deposit(500);
                dennis.deposit(500);
                morten.deposit(1);

                //print balance
                System.out.println("Allan account: " + allan.getBalance());
                System.out.println("Nick account: " + nick.getBalance());
                System.out.println("Dennis account: " + dennis.getBalance());
                System.out.println("Morten account: " + morten.getBalance());

                //Withdraw money
                allan.withdraw(478.5);
                nick.withdraw(478.5);
                dennis.withdraw(1);
                //En skiferie er jo dyr :-)
                morten.withdraw(18000);

                //print balance
                System.out.println("Allan new account: " + allan.getBalance());
                System.out.println("Nick new account: " + nick.getBalance());
                System.out.println("Dennis new account: " + dennis.getBalance());
                System.out.println("Morten new account: " + morten.getBalance());
					 
					 /*
					 Account morten = bank.getAccount("Morten");
					 morten.deposit(1);
					 morten = bank.getAccount("Morten");
					 morten.withdraw(18000);
					 System.out.println("Morten account: " + morten.getBalance());
					 morten = bank.getAccount("Morten");
					 System.out.println("Morten account: " + morten.getBalance());
					 */
            } catch (Exception ex) {
                System.out.println("Failed to do operations on RMI Bank!\n");
                System.out.println(ex);
            }

        }
    }
}
